package com.yshow.common.aspect;

import com.yshow.common.annotation.MyAnnotation;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/10/9 11:40
 */

@Slf4j
@Component
@Aspect
public class MyAnnotationAspect {

    @Pointcut("@annotation(com.yshow.common.annotation.MyAnnotation)")
    public void myPointcut(){

    }


    @Before("myPointcut()")
    public void before(JoinPoint joinPoint){
        log.info("执行方法前");

        Signature signature = joinPoint.getSignature();
        log.info("获得的签名为"+signature);

        MethodSignature signature1 = (MethodSignature) joinPoint.getSignature();
        log.info("获得的签名2为"+signature1);

        Method method =
                signature1.getMethod();


        MyAnnotation annotation = method.getAnnotation(MyAnnotation.class);
        String name = annotation.name();
        int num = annotation.num();
        log.info("获得的name和num值为{}----{}",name,num);
    }






}
